package com.jprocms.module.cms.dal.dataobject.globalconfig;

import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.jpro.framework.mybatis.core.dataobject.BaseDO;
import com.jprocms.module.cms.api.dto.*;
import com.jprocms.module.cms.framework.mybatisplus.JacksonTypeIgnoreUnknownHandler;
import com.jprocms.module.cms.util.EnvUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.hibernate.validator.constraints.Length;
import org.springframework.lang.Nullable;

import java.io.Serializable;

/**
 * 系统配置 DO
 *
 * @author jprocms
 */
@TableName(value = "cms_global_config", autoResultMap = true)
@KeySequence("cms_global_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GlobalConfigDO extends BaseDO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * ID
     */
    @TableId
    private Integer id;
    /**
     * 端口号
     */
    private Integer port;
    /**
     * 上传配置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private UploadConfig uploadConfig;
    /**
     * 账户安全配置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private SecurityConfig securityConfig;
    /**
     * 注册设置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private RegisterConfig registerConfig;

    /**
     * 邮箱配置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private EmailConfig emailConfig;

    /**
     * 其他配置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private OtherConfig otherConfig = new OtherConfig();

    /**
     * 访问后台限制IP配置
     */
    @TableField(typeHandler = JacksonTypeIgnoreUnknownHandler.class)
    private AdminIpConfig adminIpConfig = new AdminIpConfig();

    /**
     * 上传存储点设置
     */
    private Integer uploadStoreConfigId;

    /**
     * HTML静态页存储点设置
     */
    private Integer htmlStoreConfigId;

    /**
     * HTML静态页访问前缀
     */
    private String htmlPrefix;
    /**
     * 栏目URL地址前缀
     */
    @Length(max = 50)
    @Nullable
    @Schema(description = "栏目URL地址前缀")
    private String channelUrlPrefix;

    /**
     * 内容URL地址前缀
     */
    @Length(max = 50)
    @Nullable
    @Schema(description = "内容URL地址前缀")
    private String contentUrlPrefix;

    /**
     * 模板存储配置ID
     */
    private Integer tplStoreConfigId;

    /**
     * 模板存储配置域名 来自infra_file_config config 配置的域名同步
     */
    private String tplStoreConfigDomain;


    /**
     * 文件上传后缀黑名单
     */
    @TableField(exist = false)
    private String uploadsBlacklist = "";


    @JsonIgnore
    public int getGrade() {
        return EnvUtil.getGrade();
    }

}
